﻿// -------------------------------------------------------------------------
//    @FileName         :    NFPlayerPacketSendUtil.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-22
//    @Email            :    445267987@qq.com
//    @Module           :    NFPlayerPacketSendUtil
//
// -------------------------------------------------------------------------

#include "NFPlayerPacketSendUtil.h"

#include <NFPlayerMgr.h>
#include <Base/NFPacketSendUtil.h>
#include "NFPlayer.h"
#include "proto_common_bag.nanopb.h"

int NFPlayerPacketSendUtil::NotifyKickOff(NFPlayer* pPlayer, int iReason, const char* reasonStr)
{
    CHECK_NULL(0, pPlayer);

    proto_ff::Proto_CSRsp oCSRsp;
    proto_ff::Proto_CSKickOff* pKickOff = oCSRsp.mutable_kick_off();
    pKickOff->set_reason(iReason);
    pKickOff->set_reason_str(reasonStr);
    NFPacketSendUtil::SendToClient(pPlayer->GetClientSession(), proto_ff::E_CS_KICKOFF_NTF, &oCSRsp);

    return 0;
}

int NFPlayerPacketSendUtil::NotifyGetRoleRsp(NFPlayer* pPlayer, BagPage* pStorage)
{
    CHECK_NULL(0, pPlayer);

    proto_ff::Proto_CSRsp rsp;
    proto_ff::Proto_CSGetRoleRsp* pGetRoleRsp = rsp.mutable_get_role();

    if (pStorage)
    {
        pStorage->ToPb(pGetRoleRsp->mutable_item_data()->mutable_storage_data());
    }
    pPlayer->MakePlayerDataCS(pGetRoleRsp);
    pPlayer->SaveRoleSimpleInfo(pGetRoleRsp->mutable_simple_info());
    NFSession* pSession = pPlayer->GetClientSession();
    CHECK_NULL(0, pSession);

    pGetRoleRsp->set_is_gm(false);

    NFPacketSendUtil::SendToClient(pPlayer, proto_ff::E_CS_GETROLE_RSP, &rsp);
    return 0;
}
